﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string name = UserName.Text;
            string pwd = PassWord.Text;
            string email = Email.Text;
            string a = Adtro.Text;

            string con = "server=.;uid=sa;pwd=123456;database=Student_db";
            SqlConnection constr = new SqlConnection(con);
            constr.Open();

            string sql = "insert into StudentInfo(stu_name,password,email,intro) values(@name,@pwd,@email,@adtro)";
            SqlParameter[] pars = {
            new SqlParameter("@name",name),
            new SqlParameter("@pwd",pwd),
            new SqlParameter("@email",email),
            new SqlParameter("@adtro",a)
            };
            SqlCommand cmd = new SqlCommand(sql,constr);
            cmd.Parameters.AddRange(pars);
            int result = cmd.ExecuteNonQuery();
            if (result>0)
            {
                Literal1.Text = "注册成功<a href='WebForm1.aspx'>去登录<a/>";
            }
            else
            {
                Literal1.Text = "注册失败";
            }
            
        }
    }
}